package info.qingshui.browser.hk;

import android.graphics.Bitmap;
import android.util.Log;
import android.view.animation.*;

import android.webkit.WebChromeClient;
import android.webkit.WebView;
import info.qingshui.browser.R;


public class HKWebChromeClient extends WebChromeClient {
	HKActivity hkActivity;


	
	Animation animation;
	
	public HKWebChromeClient(HKActivity hkActivity) {
		super();
		this.hkActivity = hkActivity;
	}


	
	
	public void onProgressChanged(WebView view, int progress) {
		hkActivity.setCurrentProgress( progress  );
		hkActivity.updateProgress();
		if( progress >= 30) {
			//允许加载图片
			hkActivity.getWebview().getSettings().setBlockNetworkImage( false );  
		}
		if( progress == 100 ) {
			hkActivity.getSetting().setWebViewDefaultSettings(view);
		}
		//Log.d(HKWebChromeClient.class.getSimpleName(), "onProgressChanged " + progress); 
	}  
	
	public void onReceivedTitle(WebView view, String title)  {
		if( hkActivity.getCurrentProgress() == 0 ) {
			//没有在加载页面
			return;
		}
		hkActivity.setOtherProgress(hkActivity.getOtherProgress() + 5);
		hkActivity.updateProgress();
		Log.d(HKWebChromeClient.class.getSimpleName(), "onReceivedTitle " + title);
	}
	
	public void onReceivedIcon(WebView view, Bitmap icon) {
		if( hkActivity.getCurrentProgress() == 0 ) {
			//没有在加载页面
			return;
		}
		hkActivity.setOtherProgress(hkActivity.getOtherProgress() + 5);
		hkActivity.updateProgress();
		Log.d(HKWebChromeClient.class.getSimpleName(), "onReceivedIcon");
	}
	
	public void onReceivedTouchIconUrl(WebView view, String url,
            boolean precomposed) {
		if( hkActivity.getCurrentProgress() == 0 ) {
			//没有在加载页面
			return;
		}
		hkActivity.setOtherProgress(hkActivity.getOtherProgress() + 5);
		hkActivity.updateProgress();
		Log.d(HKWebChromeClient.class.getSimpleName(), "onReceivedTouchIconUrl " + url);
	}
	
//    public void onProgressChanged(WebView view, int newProgress) {        
//    	pb=(ProgressBar)activity.findViewById(R.id.pb);        
//    	pb.setMax(100);        
//    	if(newProgress<100){            
//    		if(pb.getVisibility()==View.GONE)                
//    			pb.setVisibility(View.VISIBLE);            
//    		pb.setProgress(newProgress);        
//    	}else{            
//    		pb.setProgress(100);            
//    		animation=AnimationUtils.loadAnimation(activity, R.anim.animation);            // 运行动画 animation              
//    		pb.startAnimation(animation);              // 将 spinner 的可见性设置为不可见状态             
//    		pb.setVisibility(View.INVISIBLE);         
//    	}                
//    	super.onProgressChanged(view, newProgress);   
//    	//super.o
//    }    
//    
    
 
//    public void onReceivedTitle(WebView view, String title) {        
//    	//hkActivity.setTitle(title);
//    	super.onReceivedTitle(view, title);    
//    	
//    }


}

